<template>
	<view>
		<view class="tab_nav1" style="background: #fff;z-index: 999;width: 100%;position: relative;">
			<nav-bar nav_btn="back" :showShare="true" @inputMethods="fresher" :placeholder="placeholder" :color="color"
				:background="background" :auto_img="img"></nav-bar>
		</view>
		<view class="list_max_box">
			<view class="bot_list_goods_box" v-if="storeList.length > 0" v-for="(item,index) in storeList"
				@click="onGoods(item.is_photography,item.id,item.shopname)" :key="item.id">
				<view class="flex">
					<view class="portrait">
						<image class="w100 h100" :src="item.avatar_url" mode=""></image>
					</view>
					<view class="right_txtbox">
						<view class="store_name f800 s28">
							{{item.shopname}}
						</view>
						<view class="goods_num_fangke_num f500 s22 family">
							商品{{item.goods}} &nbsp;| &nbsp;访客{{item.views}}
						</view>
						<view class="xinxi_phone_img flex">
							<view class="xinxi_img" @click.stop="goPinglun(item.id)">
								<image class="w100 h100" src="../../static/store/xinxi.png" mode=""></image>
							</view>
							<view class="phone_img" @click.stop="onPhone(item.mobile)">
								<image class="w100 h100" src="../../static/store/phone.png" mode=""></image>
							</view>
							<view
								:class="[item.follow == 0 ? 'guanzhu_btn' : 'guanzhu_btn_active','s26','f500','family','txtali']"
								@click.stop="guanZhu(item.id,item.follow,index)">
								{{item.follow == 0 ? '关注' : '已关注'}}
							</view>
						</view>
					</view>
				</view>
				<view class="bottom_dingwei flex" @click.stop="getOpenLoaction(item.latitude,item.longitude)">
					<view class="weizhi_img">
						<image class="w100 h100" src="../../static/store/dingwei.png" mode=""></image>
					</view>
					<view class="dingwei_txt f500 s22 family">
						<block v-if="item.latitude && item.longitude">距离{{item.distance}}</block>
						&nbsp;&nbsp;{{item.city}}
					</view>
				</view>
			</view>
			<view class="no_list" v-if="storeList.length == 0">
				没有更多数据
			</view>
			<!-- <view class="" @click="goRequest">
123
			</view> -->
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				color: 'white',
				img: '../pages/filePages/static/left_jian_back.png',
				img: '/static/tab_jian.png',
				background: '#fff',
				placeholder: '商品名/店铺名/商品种类/关键字',
				keywords: '',
				storeList: [],
			}
		},
		methods: {
			goRequest() {
				const requestTask = uni.request({
					url: 'http://3028c5c5.r18.cpolar.top/api/doctor/send_gpt?message=一千字的作文',
					headers: {
						"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
					},
					enableChunked:true,
					responseType: 'text',
					success: res => {
						return false
					}
				})
				requestTask.onChunkReceived(res => {
					let buf = Buffer.from(res.data);
					const str = buf.toString();
				})
			},
			// 搜索
			fresher(e) {
				this.keywords = e.detail.value;
				this.storeList = []
				this.$request({
					url: 'shop/lists',
					data: {
						search: this.keywords
					}
				}).then(res => {
					let array = []
					let array1 = []
					this.totalNum = res.data.current_page;
					this.items = res.data.data.data.map((item, index) => {
						if (item.follow == 1) {
							array.push(item)
						} else {
							array1.push(item)
						}
					})
					this.storeList = [...array, ...this.storeList, ...array1]
				})
			},
			// 调取导航
			getOpenLoaction(latitude, longitude) {
				if (!latitude && !longitude) {
					uni.showToast({
						title: "当前店铺未开启定位！",
						icon: "none"
					})
					return false
				}
				uni.openLocation({
					latitude: Number(latitude),
					longitude: Number(longitude),
					success: function() {
						return false
					},
					fail(error) {
						return false
					}
				});
			},
			// 跳转店铺详情
			onGoods(flag, id, name) {
				let shopDetail = {
					shopname: name,
					id: id,
					flag: flag
				}
				let that = this
				if (flag != 1) {
					uni.navigateTo({
						url: '/pages/filePages/storePages/index'
					})
					that.$store.commit("getDataShop", shopDetail)

				} else {
					that.$store.commit("getDataShopname", shopDetail)
					uni.navigateTo({
						url: '/pages/store/goodsList'
					})
				}
			},
			// 关注/取消关注
			guanZhu(id, follow, index) {
				this.$request({
					url: 'shop/follow',
					method: 'POST',
					data: {
						id: id
					}
				}).then(res => {
					if (res.statusCode == 200) {
						let item = this.storeList[index]
						if (item.follow == 1) {
							uni.showToast({
								title: '取消关注',
								icon: 'none',
								duration: 2000,
							})
							item.follow = 0
						} else {
							uni.showToast({
								title: '关注成功',
								icon: 'none',
								duration: 2000,
							})
							item.follow = 1
						}
						this.storeList.splice(index, 1, item)
					}
				})
			},
		}
	}
</script>
<style scoped lang="scss">
	//店铺列表
	.list_max_box {
		background-color: #FFFFFF;
		padding: 30upx 0 30upx 0;
		padding: 0 0 30upx 0;

		.bot_list_goods_box {
			width: 666upx;
			height: 238upx;
			background: #F4F5F9;
			border-radius: 16upx 16upx 16upx 16upx;
			margin: 20upx auto;
			padding: 20upx 0 0 20upx;

			.portrait {
				width: 160upx;
				height: 160upx;
				border-radius: 16upx 16upx 16upx 16upx;
				overflow: hidden;
			}

			.right_txtbox {
				margin-left: 28upx;

				.store_name {
					font-family: PingFang SC-Heavy, PingFang SC;
					color: #333333;
					margin-top: 8upx;
				}

				.goods_num_fangke_num {
					color: #666666;
					margin-top: 20upx;
				}

				.xinxi_phone_img {
					margin-top: 20upx;

					.xinxi_img {
						width: 54upx;
						height: 54upx;
					}

					.phone_img {
						width: 54upx;
						height: 54upx;
						margin-left: 56upx;
					}

					.guanzhu_btn {
						width: 116upx;
						height: 48upx;
						border-radius: 8upx 8upx 8upx 8upx;
						border: 2upx solid #EB8787;
						color: #EB8787;
						position: absolute;
						margin-top: -24rpx;
						right: 56rpx;
						line-height: 48upx;

					}

					.guanzhu_btn_active {
						width: 116upx;
						height: 48upx;
						border-radius: 8upx 8upx 8upx 8upx;
						background-color: #EB8787;
						color: #fff;
						position: absolute;
						margin-top: -24rpx;
						right: 56rpx;
						line-height: 48upx;
					}
				}
			}

			.bottom_dingwei {
				margin-top: 14upx;

				.weizhi_img {
					width: 26upx;
					height: 26upx;
				}

				.dingwei_txt {
					color: #E29D48;
					margin-top: 4upx;
					margin-left: 8upx;
				}
			}
		}

		.bot_list_goods_box:first-child {
			margin-top: 0upx;
		}

		.no_list {
			text-align: center;
			margin-top: 60%;
		}
	}
	.header_back {
		height: 296upx;
		position: absolute;
	}

	.title {
		font-size: 32upx;
		color: #FFFFFF;
		text-align: center;
	}

	.header_box {
		position: relative;

		.uni-input {
			width: 608upx;
			height: 68upx;
			background: #FFFFFF;
			border-radius: 8upx 8upx 8upx 8upx;
			margin: 48upx auto;
			margin-bottom: 0;
			padding-left: 78upx;
			color: #CCCCCC;
		}

		.ipt_sousuo {
			width: 40upx;
			height: 40upx;
			position: relative;
			top: -52upx;
			left: 56upx;
		}

		.nav_list {
			margin-top: -16upx;
			padding-left: 36upx;

			.nav_list_box {
				width: 630upx;

				.scroll-view_H {
					white-space: nowrap;

					.scroll-view-item_H {
						display: inline-block;
						margin-left: 58upx;

						.nav_list_txt {
							width: 104upx;
							height: 36upx;
							font-size: 26upx;
							font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 500;
							color: #FFFFFF;
						}

						.nav_txt_active {
							font-size: 26upx;
							font-family: PingFang SC-Heavy, PingFang SC;
							font-weight: 800;
							color: #FFFFFF;
						}

						.nav_list_botxian {
							width: 46upx;
							border-bottom: 6upx solid #FFFFFF;
							margin: 6upx auto;
						}
					}

					.scroll-view-item_H:nth-child(1) {
						margin-left: 0rpx;
					}
				}
			}

			.fenlei_box {
				width: 34upx;
				height: 34upx;
				margin-right: 30rpx;
				margin-top: 6rpx;
			}
		}
	}
</style>